﻿@{
    ViewBag.Title = "OAuth2 Debug Tool";
}

@section headers {
    <script type="text/javascript">
        function delCurrent(src) {
            $(src).parent().parent().remove();
        }

        function addParam() {
            var tr = "<tr><td><input type=\"text\" name=\"k\" /></td><td>:</td><td><input type=\"text\" name=\"v\" /></td><td><a href=\"#\" onclick=\"javascript: delCurrent(this); return false;\">x</a></td></tr>";
            $("#ptab").append(tr);
        }

        function addBDParam() {
            var tr = "<tr><td><input type=\"text\" name=\"bdKey\" /></td><td>:</td><td><input type=\"file\" name=\"bdValue\" /></td><td><a href=\"#\" onclick=\"javascript: delCurrent(this); return false;\">x</a></td></tr>";
            $("#ptab2").append(tr);
        }

        function OnSuccess(data) {
            alert("OnSuccessCallback");
            window.t = data;
            $("#data").val(data.ret);
        }

        function ClearReturns() {
            $("#data").val("");
        }
    </script>
    <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
    @*<script src="@Url.Content("~/Scripts/MicrosoftAjax.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/MicrosoftMvcAjax.js")" type="text/javascript"></script>*@
}

<h2>OAuth2 Debug Tool</h2>
<div>
    <div>Returns: <a href="#" onclick="javascript: ClearReturns(); return false;">Clear</a></div>
    <div>
        <textarea id="data" style="width:800px;height:410px;"></textarea>
    </div>
</div>
<div>
@using (Ajax.BeginForm("Call", null, new AjaxOptions { OnSuccess = "OnSuccess" }, new { enctype = "multipart/form-data" }))
{
    
    <table style="margin-top:24px;">
        <tr>
            <td>Access Token</td>
            <td>:</td>
            @{
    dynamic accessToken = Session["accessToken"] as dynamic;
    var tmpAccessToken = string.Empty;

    if (accessToken != null)
    {
        tmpAccessToken = accessToken.access_token;
    }
            }
            <td>@Html.TextBox("accessToken", tmpAccessToken, new { style = "width:350px" })</td>
        </tr>
        <tr>
            <td>Weibo Type</td>
            <td>:</td>
            <td>

            @{
    var isTencent = accessToken.openid != null;
            }

                <input id="wbType1" name="wbType" type="radio" value="tencent" @if (isTencent) { Write(MvcHtmlString.Create("checked=\"checked\"")); } else { Write(""); } /><label for="wbType1">Tencent</label>
                <input id="wbType2" name="wbType" type="radio" value="sina" @if (!isTencent) { Write(MvcHtmlString.Create("checked=\"checked\"")); } else { Write(""); } /><label for="wbType2">Sina</label>
            </td>
        </tr>
        <tr>
            <td>http method</td>
            <td>:</td>
            <td>
                <input id="httpmethod1" name="httpMethod" type="radio" value="get" checked="checked" /><label for="httpmethod1">GET</label>
                <input id="httpmethod2" name="httpMethod" type="radio" value="post" /><label for="httpmethod2">POST</label>
            </td>
        </tr>
        <tr>
            <td>api url</td>
            <td>:</td>
            <td>@Html.TextBox("apiUrl", null, new { style = "width:500px" })</td>
        </tr>
    </table>
    <hr />
    <div style="margin-top: 12px;">
        api params: 
        <table id="ptab">
            <tr>
                <th>key</th>
                <th>&nbsp;</th>
                <th>value</th>
                <th>&nbsp;</th>
            </tr>
            <tr>
                <td><input type="text" name="k" /></td>
                <td>:</td>
                <td><input type="text" name="v" /></td>
                <td><a href="#" onclick="javascript: delCurrent(this); return false;">x</a></td>
            </tr>
            <tr>
                <td><input type="text" name="k" /></td>
                <td>:</td>
                <td><input type="text" name="v" /></td>
                <td><a href="#" onclick="javascript: delCurrent(this); return false;">x</a></td>
            </tr>
            <tr>
                <td><input type="text" name="k" /></td>
                <td>:</td>
                <td><input type="text" name="v" /></td>
                <td><a href="#" onclick="javascript: delCurrent(this); return false;">x</a></td>
            </tr>
        </table>
        <div>
            <div><a href="#" onclick="javascript: addParam(); return false;">添加</a></div>
        </div>
    </div>
    @*<div style="margin-top: 12px;">
        api file params: 
        <table id="ptab2">
            <tr>
                <th>key</th>
                <th>&nbsp;</th>
                <th>value</th>
                <th>&nbsp;</th>
            </tr>
            <tr>
                <td><input type="text" name="bdKey" /></td>
                <td>:</td>
                <td><input type="file" name="bdValue" /></td>
                <td><a href="#" onclick="javascript: delCurrent(this); return false;">x</a></td>
            </tr>
        </table>
        <div>
            <div><a href="#" onclick="javascript: addBDParam(); return false;">添加</a></div>
        </div>
    </div>*@
    <div style="margin-top: 18px;">
        <button type="submit" id="btnCall" value="do">Call</button>&nbsp;&nbsp;&nbsp;&nbsp;
    </div>
    <div style="margin-top: 40px;">
        <h2>Dev Guide</h2>

        <table>
            <tr>
                <td>Sina</td>
                <td>
                    <a href="http://open.t.sina.com.cn/wiki/API%E6%96%87%E6%A1%A3_V2" target="_blank">API</a> <a href="http://open.t.sina.com.cn/wiki/Error_code" target="_blank">Error Code</a>
                </td>
            </tr>
            <tr>
                <td>Tencent</td>
                <td>
                    <a href="http://wiki.open.t.qq.com/index.php/API%E6%96%87%E6%A1%A3" target="_blank">API</a> <a href="http://wiki.open.t.qq.com/index.php/%E8%BF%94%E5%9B%9E%E9%94%99%E8%AF%AF%E7%A0%81%E8%AF%B4%E6%98%8E" target="_blank">Error Code</a> <a href="http://wiki.open.t.qq.com/index.php/%E9%94%99%E8%AF%AF%E7%A0%81%E8%AF%B4%E6%98%8E" target="_blank">开放平台</a>
                </td>
            </tr>
            @*<tr>
                <td>NetEase</td>
                <td>
                    <a href="http://open.t.163.com/wiki/index.php?title=Document" target="_blank">API</a> <a href="http://open.t.163.com/wiki/index.php?title=%E9%94%99%E8%AF%AF%E4%BB%A3%E7%A0%81(_error_code_)" target="_blank">Error Code</a>
                </td>
            </tr>*@
        </table>
    </div>
}
</div>
